﻿<UserControl x:Class="iopt.solvency.pillarone.client.desktop.Views.ParameterDesigner"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:iopt.solvency.pillarone.client.desktop.ViewModels"
             xmlns:System="clr-namespace:System;assembly=mscorlib"
             xmlns:avalonedit="http://icsharpcode.net/sharpdevelop/avalonedit"
             xmlns:helpers="clr-namespace:iopt.solvency.pillarone.client.desktop.Helpers"
             xmlns:converters="clr-namespace:iopt.solvency.pillarone.client.desktop.Converters"
             mc:Ignorable="d"  Background="White"
             d:DesignHeight="300" d:DesignWidth="300">

    <!--<UserControl.DataContext>
         <local:ViewModelParametres/>
         </UserControl.DataContext>!-->

    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition />
            <ColumnDefinition Width="5"/>
            <ColumnDefinition  />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition/>
        </Grid.RowDefinitions>
        <StackPanel HorizontalAlignment="Left" Orientation="Horizontal" Grid.ColumnSpan="3">
            <Button Content="Ajouter une variable"  Width="149" Margin="5,5,0,5" d:LayoutOverrides="Height" Command="{Binding AddParamCommand, Mode=OneWay}"/>
            <Button Content="Generer le code" Width="149" Margin="5,5,0,5" d:LayoutOverrides="Height" Command="{Binding GenerateCodeCommand, Mode=OneWay}"/>
            <Button Content="Ajouter une variable" Width="149" Margin="5,5,0,5" d:LayoutOverrides="Height" Command="{Binding AddParamCommand, Mode=OneWay}" Visibility="Collapsed"/>
        </StackPanel>
        <TabControl Grid.Row="1" Grid.Column="2" Margin="5" ItemsSource="{Binding Params}">
            <TabControl.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Left" >
                        <TextBlock Text="{Binding Name}" VerticalAlignment="Center" FontSize="16" />
                        <CheckBox VerticalAlignment="Center" Margin="10,0,0,0" IsChecked="{Binding AutoGenerateCode}" />
                    </StackPanel>
                </DataTemplate>
            </TabControl.ItemTemplate>
            <TabControl.ContentTemplate>
                <DataTemplate>
                    <Grid>
                        <avalonedit:TextEditor FontWeight="Bold" FontStyle="Italic" FontSize="14" FontFamily="Calibri"  Background="White" >
                            <avalonedit:TextEditor.SyntaxHighlighting>
                                <Binding Source=".vb">
                                    <Binding.Converter>
                                        <converters:HighlightingDefinitionConverter />
                                    </Binding.Converter>
                                </Binding>
                            </avalonedit:TextEditor.SyntaxHighlighting>

                            <avalonedit:TextEditor.Document>
                                <Binding Path="Code">
                                    <Binding.Converter>
                                        <converters:DocumentConverter />
                                    </Binding.Converter>
                                </Binding>
                            </avalonedit:TextEditor.Document>
                        </avalonedit:TextEditor>
                    </Grid>
                </DataTemplate>
            </TabControl.ContentTemplate>
        </TabControl>
        <ListBox Margin="5" Grid.Row="1" ItemsSource="{Binding Params}" ItemTemplate="{DynamicResource ParametreTemplate}">
            <ListBox.Resources>
                <DataTemplate x:Key="ParametreTemplate">
                    <Expander IsExpanded="{Binding Extras.Visible}" d:DesignWidth="401" d:DesignHeight="186" MinWidth="450">
                        <Expander.Header>
                            <StackPanel Orientation="Horizontal">
                                <TextBox Text="{Binding Name}" Background="{x:Null}" BorderBrush="{x:Null}" VerticalContentAlignment="Center" FontStyle="Italic" FontWeight="Bold" MinWidth="150" />
                            </StackPanel>
                        </Expander.Header>
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition  />
                                <ColumnDefinition />
                                <ColumnDefinition />
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>

                                <RowDefinition />
                                <RowDefinition />
                                <RowDefinition />
                                <RowDefinition />
                                <RowDefinition Height="Auto" />
                            </Grid.RowDefinitions>
                            <CheckBox Content="IsSingleton" Width="110" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,5" IsChecked="{Binding IsSingleton, Mode=TwoWay}"/>
                            <CheckBox Content="IsVector" Grid.Row="1" Width="110" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,5" IsChecked="{Binding IsVector, Mode=TwoWay}"/>
                            <CheckBox Content="IsMatrix" Grid.Row="2" Width="110" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,5" IsChecked="{Binding IsMatrix, Mode=TwoWay}"/>
                            <CheckBox Content="IsTable" Grid.Column="1" Width="110" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,5" IsChecked="{Binding IsTable, Mode=TwoWay}"/>
                            <CheckBox Content="IsUnique" Grid.Row="1" Grid.Column="1" Width="110" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,5" IsChecked="{Binding IsUnique, Mode=TwoWay}"/>
                            <CheckBox Content="IsSegmentable" Grid.Row="2" Grid.Column="1" Width="110" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,5" IsChecked="{Binding IsSegmentable, Mode=TwoWay}"/>
                            <CheckBox Content="IsCalculable" Grid.Column="2" Width="110" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,5" IsChecked="{Binding IsCalculable, Mode=TwoWay}"/>
                            <CheckBox Content="IsFixed" Grid.Row="1" Grid.Column="2" Width="110" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,5" IsChecked="{Binding IsFixed, Mode=TwoWay}"/>
                            <CheckBox Content="IsSheet" Grid.Row="2" Grid.Column="2" Width="110" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,5" IsChecked="{Binding IsSheet, Mode=TwoWay}"/>
                            <StackPanel Grid.ColumnSpan="1"  Grid.Row="3" Orientation="Horizontal" >
                                <TextBlock Text="Type" VerticalAlignment="Center" Margin="12,0,0,0" />
                                <ComboBox VerticalAlignment="Center" Margin="15,0,0,0"  SelectedItem="{Binding UnderlyingType, Mode=TwoWay}"   >
                                    <ComboBox.ItemsSource>
                                        <x:Array Type="{x:Type local:ModelParamUnderLyingType}">
                                            <local:ModelParamUnderLyingType>Double</local:ModelParamUnderLyingType>
                                            <local:ModelParamUnderLyingType>Case</local:ModelParamUnderLyingType>
                                            <local:ModelParamUnderLyingType>Boolean</local:ModelParamUnderLyingType>
                                            <local:ModelParamUnderLyingType>Time</local:ModelParamUnderLyingType>
                                            <local:ModelParamUnderLyingType>Date</local:ModelParamUnderLyingType>
                                            <local:ModelParamUnderLyingType>Mixed</local:ModelParamUnderLyingType>
                                            <local:ModelParamUnderLyingType>Uncertain</local:ModelParamUnderLyingType>
                                        </x:Array>
                                    </ComboBox.ItemsSource>
                                </ComboBox>
                            </StackPanel>
                            <CheckBox  HorizontalAlignment="Stretch" d:LayoutOverrides="Height" Grid.Row="3" Grid.Column="1" Grid.ColumnSpan="2" VerticalAlignment="Center" Margin="20,5" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch">
                                <Grid>
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="Auto" />
                                        <RowDefinition  />
                                    </Grid.RowDefinitions>
                                    <TextBlock Text="Contrainte" />
                                    <TextBox Grid.Row="1" Text="{Binding Path=Constraint, Mode=TwoWay}" IsEnabled="{Binding RelativeSource={RelativeSource AncestorType=CheckBox}, Path=IsChecked}"  />
                                </Grid>
                            </CheckBox>
                            <CheckBox  HorizontalAlignment="Stretch" d:LayoutOverrides="Height" Grid.Row="4" Grid.Column="0" Grid.ColumnSpan="3" VerticalAlignment="Center" Margin="20,5" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch">
                                <Grid>
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="Auto" />
                                        <RowDefinition  />
                                    </Grid.RowDefinitions>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition />
                                        <ColumnDefinition />
                                    </Grid.ColumnDefinitions>
                                    <TextBlock Text="Format" />
                                    <TextBox Grid.Row="1" Text="{Binding Path=Format, Mode=TwoWay}" IsEnabled="{Binding RelativeSource={RelativeSource AncestorType=CheckBox}, Path=IsChecked}"  />
                                    <TextBlock Grid.Column="1" Text="Légende" />
                                    <TextBox AcceptsReturn="True" Grid.Row="1" Grid.Column="1" Text="{Binding Path=Legend, Mode=TwoWay}" IsEnabled="{Binding RelativeSource={RelativeSource AncestorType=CheckBox}, Path=IsChecked}"  />
                                </Grid>
                            </CheckBox>
                        </Grid>
                    </Expander>

                </DataTemplate>
            </ListBox.Resources>
        </ListBox>
        <GridSplitter HorizontalAlignment="Stretch" Width="5" Grid.Column="1" Grid.Row="1"/>
    </Grid>

</UserControl>
